//
//  JMMeHeader.m
//  NewiOSProject
//
//  Created by li on 2023/9/12.
//  Copyright © 2023 范智渊. All rights reserved.
//

#import "JMMeHeader.h"
#import "CustomStackView.h"
#import "LayoutView.h"
#import "UIView+PopupProtocol.h"

@implementation JMMeHeader

- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        [self setupViews];
        self.backgroundColor = WhiteColor();
    }
    return self;
}

- (void)setupViews {
    
    UIStackView *stackView = [UIStackView new];
    stackView.axis = UILayoutConstraintAxisVertical;
    stackView.translatesAutoresizingMaskIntoConstraints = NO;
    [self addSubview:stackView];
    [NSLayoutConstraint activateConstraints:@[
        [stackView.topAnchor constraintEqualToAnchor:self.topAnchor],
        [stackView.leftAnchor constraintEqualToAnchor:self.leftAnchor],
        [stackView.widthAnchor constraintEqualToAnchor:self.widthAnchor],
        [stackView.heightAnchor constraintEqualToAnchor:self.heightAnchor]
    ]];
    
    UIImageView *bgImageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"Slice 2"]];
//    [bgImageView.heightAnchor constraintEqualToConstant:310].active = YES;
    bgImageView.contentMode = UIViewContentModeScaleAspectFill;
    [stackView addArrangedSubview: bgImageView];
    
    
    CustomStackView *userStack = [CustomStackView init:(UILayoutConstraintAxisHorizontal)];
    userStack.spacing = 16;
    
    UIImageView *avatar = [UIImageView new];
    self.avatar = avatar;
    avatar.image = [UIImage imageNamed:@"wd"];
    avatar.contentMode = UIViewContentModeScaleAspectFill;
    [avatar.widthAnchor constraintEqualToConstant:72].active = YES;
    [avatar.heightAnchor constraintEqualToConstant:72].active = YES;
    [userStack addArrangedSubview:avatar];
    avatar.cornerRadius = 36;
    avatar.layer.borderColor = Hex_Str_COLOR(@"#A8B1FE").CGColor;
    avatar.layer.borderWidth = 4;
    avatar.backgroundColor = Hex_Str_COLOR(@"#3C57F8");
    
    UILabel *nickName = [UILabel new];
    nickName.font = [UIFont systemFontOfSize:30];
    nickName.textColor = [UIColor colorWithHexString:@"#ffffff"];
//    nickName.text = @"nickName";
    [userStack addArrangedSubview:nickName];
    self.nickName = nickName;
    
    [bgImageView addSubview:userStack];
    userStack.translatesAutoresizingMaskIntoConstraints = NO;
    [NSLayoutConstraint activateConstraints:@[
        [userStack.leftAnchor constraintEqualToAnchor:bgImageView.leftAnchor constant: 16],
        [userStack.rightAnchor constraintEqualToAnchor:bgImageView.rightAnchor constant: -16],
        [userStack.bottomAnchor constraintEqualToAnchor:bgImageView.bottomAnchor constant:-140],
    ]];
    
    
    
    
    CustomStackView *moneyStack = [CustomStackView init:(UILayoutConstraintAxisHorizontal)];
    moneyStack.spacing =19;
    moneyStack.distribution = UIStackViewDistributionFillEqually;
    for (NSInteger i = 0; i < 2; i ++) {
        LayoutView *stack = [LayoutView new];
        stack.layoutViewAlignment = LayoutViewAlignmentCenter;
        stack.contentView.axis = UILayoutConstraintAxisVertical;
        stack.contentView.spacing = 12;
        [stack.widthAnchor constraintEqualToConstant:(kAppW()-48-19)/2];
        [stack.heightAnchor constraintEqualToConstant:103];
        stack.cornerRadius = 4;
        
        UILabel *value = [UILabel new];
        value.font = mediumFont(22);
        value.textAlignment = NSTextAlignmentLeft;
        [stack addContentView:value];
        
        UILabel *key = [UILabel new];
        key.font = mediumFont(12);
        key.textAlignment = NSTextAlignmentLeft;
        [stack addContentView:key];
       
        if (i == 0) {
            key.text = @"Cuota disponible($)      ";
            value.text = @"--";
            self.cuotaDisponible =  value;
            [stack.contentBackgroundView setImage:ImageNamed(@"wd-ke yon pei e")];
            value.textColor = [UIColor colorWithHexString:@"#A27430"];
            key.textColor = value.textColor;

        }else if (i == 1)  {
            key.text = @"Monto por reembolsar($)";
            value.text = @"--";
            self.montoPorReembolsar = value;
            [stack.contentBackgroundView setImage:ImageNamed(@"wd-dai huan")];
            value.textColor = [UIColor colorWithHexString:@"#3C57F8"];
            key.textColor = value.textColor;
        }
        
        [moneyStack addArrangedSubview:stack];
    }
    [stackView addSubview:moneyStack];

    moneyStack.translatesAutoresizingMaskIntoConstraints = NO;
    [NSLayoutConstraint activateConstraints:@[
        [moneyStack.topAnchor constraintEqualToAnchor:avatar.bottomAnchor constant:38],
        [moneyStack.centerXAnchor constraintEqualToAnchor:bgImageView.centerXAnchor],
        [moneyStack.widthAnchor constraintEqualToConstant:(kAppW()-48)],
        [moneyStack.heightAnchor constraintEqualToConstant:103],
//        [moneyStack.bottomAnchor constraintEqualToAnchor:stackView.bottomAnchor constant:-24],


    ]];

}

@end
